home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6914 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mailhub.scitec.com.au!ramsesy
  2. From: ramsesy@rd.scitec.com.au (Ramses Youhana)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: a pointer problem
  5. Date: 16 Feb 1996 07:04:21 GMT
  6. Organization: SCITEC LIMITED, Sydney, Australia.
  7. Distribution: world
  8. Message-ID: <4g1a9l$l5@mailhub.scitec.com.au>
  9. References: <4errk0$4c3@srvr1.engin.umich.edu> <31120AB7.1C44@cmt.lpr.mail.carel.fi> <4et96h$k84@sparcserver.lrz-muenchen.de>
  10. NNTP-Posting-Host: scitec7.scitec.com.au
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Kurt Watzka (ua302aa@sun2.lrz-muenchen.de) wrote:
  14. > Ari Lukumies <aril@cmt.lpr.mail.carel.fi> writes:
  15.  
  16. > >Chih-Jen Lin wrote:
  17. > >> 
  18. > >> Hi,
  19. > >> 
  20. > >> This is an old problem of C. I remember a pointer may point
  21. > >> to any one address when it's declaired. Is there any way to
  22. > >> avoid this problem in ANSI C ? Or how can I let a variable be
  23. > >> NULL while it's declaired ?
  24. > >> 
  25. > >> Thanks in advance.
  26. > >> 
  27. > >> Chih-Jen Lin
  28.  
  29. > >You'll have to explicitly initialize the pointer, ANSI C (or any other standard) 
  30. > >doesn't do it for you. However, most compilers tend to initialize variables (also 
  31. > >pointers) declared outside of any function scope (or 'static' variables inside 
  32. > >functions) to zero/NULL, but I wouldn't count on it.
  33.  
  34. > I would and sometimes do count on initialization of static and global
  35. > variables, as long as I work with an ANSI C compiler. Initialization
  36. > happens "as if" through assigning 0 to the variable, so this kind of
  37. > initialization is save for pointers and floating point variables, too.
  38.  
  39. It is dangerous to rely on the compiler to do initialisation of static
  40. and global variables in embedded systems.  This is usually the case when
  41. you write your own boot code and don't include the appropriate routine(s)
  42. which read the data out of the appropriate section (sometimes called the
  43. IDATA or INITDATA section) and copies to the appropriate RAM locations
  44. to initialise your variables.
  45.  
  46. I always find it better (and safer) design to perform my own initialisations
  47. in an initialisation function.
  48.  
  49. Ramses.
  50.